import { Prisma } from "@prisma/generated-client";

export async function updateUserById(
  model: Prisma.TransactionClient["user"],
  id: number,
  data: Prisma.UserUpdateInput
): Promise<Awaited<ReturnType<Prisma.TransactionClient["user"]["update"]>>>;
export async function updateUserById(
  model: Prisma.TransactionClient["role"],
  id: number,
  data: Prisma.RoleUpdateInput
): Promise<Awaited<ReturnType<Prisma.TransactionClient["role"]["update"]>>>;
export async function updateUserById(
  model: any,
  id: number,
  data: any
): Promise<any> {
  if (!data.updatedAt) {
    data.updatedAt = new Date();
  }
  return model.update({ where: { id }, data });
}

export async function updateUsers(
  model: Prisma.TransactionClient["user"],
  ids: number[],
  data: Prisma.UserUpdateInput
): Promise<Awaited<ReturnType<Prisma.TransactionClient["user"]["updateMany"]>>>;
export async function updateUsers(
  model: Prisma.TransactionClient["role"],
  ids: number[],
  data: Prisma.RoleUpdateInput
): Promise<Awaited<ReturnType<Prisma.TransactionClient["role"]["updateMany"]>>>;
export async function updateUsers(
  model: any,
  ids: number[],
  data: any
): Promise<any> {
  if (!data.updatedAt) {
    data.updatedAt = new Date();
  }
  return model.updateMany({
    where: { id: { in: ids } },
    data,
  });
}
